<template>
  <div class="mod-menu">
    <el-form :inline="true" :model="pamars">
      <el-form-item label="提现单号">
        <el-input
          v-model="pamars.business_code"
          placeholder="提现单号"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="审核状态">
        <!-- <el-input v-model="dataForm.payment_term" placeholder="公司名称/联系人" clearable></el-input> -->
        <el-select
          v-model="pamars.verify_status"
          placeholder="请选择"
          clearable
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button @click="exportAll()">导出数据</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" row-key="Id" border style="width: 100%; ">
      <el-table-column prop="business_code" align="center" label="提现单号">
      </el-table-column>
      <!-- <el-table-column prop="public_service_points" align="center" label="提现服务积分">
      </el-table-column> -->
      <el-table-column prop="money" align="center" label="提现金额">
      </el-table-column>
      <el-table-column prop="commission_cost" align="center" label="提现手续费">
      </el-table-column>
      <!-- <el-table-column prop="payment_term" align="center" :formatter="paymentTerm" label="收款方式">

      </el-table-column> -->
      <el-table-column prop="payment_term" align="center" label="提现方式">
        <template slot-scope="scope">
          <div v-if="scope.row.payment_term == 0">
            <div>微信</div>
            <div>{{ scope.row.payee }}</div>
            <div>{{ scope.row.withdraw_mobile }}</div>
            <!-- <div>{{scope.row.withdraw_account}}</div> -->
          </div>
          <div v-if="scope.row.payment_term == 1">
            <div>支付宝</div>
            <div>{{ scope.row.payee }}</div>
            <div>{{ scope.row.withdraw_mobile }}</div>
            <!-- <div>{{scope.row.withdraw_account}}</div> -->
          </div>
          <div v-if="scope.row.payment_term == 2">
            <div>{{ scope.row.bank_name }}</div>
            <div>{{ scope.row.withdraw_account }}</div>
            <!-- <div>{{scope.row.payee}}</div>
            <div>{{scope.row.withdraw_mobile}}</div> -->
          </div>
          <div v-if="scope.row.payment_term == 3">
            <div>现金支付</div>
            <div>{{ scope.row.payee }}</div>
            <div>{{ scope.row.withdraw_mobile }}</div>
            <div>{{ scope.row.withdraw_account }}</div>
          </div>
          <div v-if="scope.row.payment_term == 4">
            <div>公益积分</div>
            <div>{{ scope.row.payee }}</div>
            <div>{{ scope.row.withdraw_mobile }}</div>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        prop="create_time"
        align="center"
        label="申请时间"
        width="180"
      >
      </el-table-column>
      <el-table-column prop="verify_status" align="center" label="审核状态">
        <template slot-scope="scope">
          <el-tag type="warning" v-if="scope.row.verify_status === 0"
            >待审核</el-tag
          >
          <el-tag type="success" v-if="scope.row.verify_status == 1"
            >审核通过</el-tag
          >
          <el-tag type="danger" v-if="scope.row.verify_status == 2"
            >审核不通过</el-tag
          >
        </template>
      </el-table-column>
      <el-table-column prop="remit_man" align="center" label="审核人">
        <template slot-scope="scope">{{
          scope.row.verify_man ? scope.row.verify_man : '暂无'
        }}</template>
      </el-table-column>
      <el-table-column prop="third_pay_code" align="center" label="交易流水号">
        <template slot-scope="scope">{{
          scope.row.third_pay_code ? scope.row.third_pay_code : '暂无'
        }}</template>
      </el-table-column>
      <el-table-column
        prop="remit_time"
        align="center"
        label="打款时间"
        width="180"
      >
        <template slot-scope="scope">{{
          scope.row.remit_time ? scope.row.remit_time : '暂无'
        }}</template>
      </el-table-column>
      <!-- <el-table-column prop="bank_name" align="center" label="打款银行">
        <template slot-scope="scope">{{scope.row.bank_name?scope.row.bank_name:'暂无'}}</template>
      </el-table-column> -->
      <el-table-column prop="remit_status" align="center" label="提现状态">
        <template slot-scope="scope">
          <el-tag type="warning" v-if="!scope.row.remit_status">未打款</el-tag>
          <el-tag type="success" v-if="scope.row.remit_status">已打款</el-tag>
        </template>
      </el-table-column>

      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        label="操作"
        width="100px"
      >
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.verify_status == 0"
            type="text"
            size="small"
            @click="addOrUpdateHandle(scope.row.id)"
            >审核</el-button
          >
          <el-button
            v-if="scope.row.verify_status == 1 && scope.row.remit_status == 0"
            type="text"
            size="small"
            @click="goRemit(scope.row)"
            >打款</el-button
          >
          <el-button
            v-if="scope.row.verify_status == 2"
            type="text"
            size="small"
            @click="goRemitView(scope.row)"
            >查看</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pamars.page"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pamars.limit"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <apply-audit
      v-if="addOrUpdateVisible"
      ref="applyAudit"
      @updataList="updataList"
    ></apply-audit>
    <remit v-if="remitOpen" ref="remitUrl" @updataList="updataList"></remit>
    <!-- 查看 -->
    <el-dialog title="查看原因" :visible.sync="dialogVisible" width="50%">
      <el-form ref="form" disabled :model="info" label-width="120px">
        <el-form-item label="审核状态">
          <el-tag type="warning" v-if="info.verify_status === 0">待审核</el-tag>
          <el-tag type="success" v-if="info.verify_status == 1"
            >审核通过</el-tag
          >
          <el-tag type="danger" v-if="info.verify_status == 2"
            >审核不通过</el-tag
          >
        </el-form-item>
        <el-form-item label="理由">
          <el-input
            v-model="info.verify_opinion"
            type="textarea"
            :rows="3"
            maxlength="50"
          ></el-input>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import Vue from 'vue'
import ApplyAudit from './apply-audit'
import remit from './remit'
import seviceApi from '@/api/serviceApi.js'
export default {
  data() {
    return {
      pamars: {
        page: 1,
        limit: 10,
        business_code: '',
        verify_status: ''
      },
      totalPage: 0,
      dataList: [],
      options: [
        {
          value: 0,
          label: '待审核'
        },
        {
          value: 1,
          label: '审核通过'
        },
        {
          value: 2,
          label: '审核不通过'
        }
      ],
      dialogVisible: false,
      info: {},
      dataListLoading: false,
      addOrUpdateVisible: false,
      remitOpen: false
    }
  },
  components: {
    ApplyAudit,
    remit
  },
  mounted() {
    this.getList()
  },
  methods: {
    goRemitView(row) {
      this.dialogVisible = true
      this.info = row
    },
    // 更新列表
    updataList(e) {
      if (e == 1) {
        this.getList()
      }
    },
    // 收款方式
    paymentTerm(row, column) {
      let status = row.payment_term
      if (status === 0) {
        return '微信'
      } else if (status === 1) {
        return '支付宝'
      } else if (status === 2) {
        return '银行线下'
      } else if (status === 3) {
        return '现金支付'
      }
    },
    // 审核
    addOrUpdateHandle(id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.applyAudit.init(id)
      })
    },
    // 打款
    goRemit(row) {
      if (row.withdraw_type == 0) {
        this.remitOpen = true
        this.$nextTick(() => {
          this.$refs.remitUrl.dataForm.bank_name = row.bank_name || ''
          this.$refs.remitUrl.init(row.id)
        })
      } else {
        this.$confirm('确定打款?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            seviceApi.getWithdrawRemit({ id: row.id }).then(res => {
              if (res && res.data.code == 200) {
                this.$message({
                  showClose: true,
                  message: '打款成功',
                  type: 'success'
                })
                this.getList()
              }
            })
          })
          .catch(() => {})
      }
    },
    getList() {
      seviceApi.getWithdrawList(this.pamars).then(res => {
        if (res && res.data.code == 200) {
          this.dataList = res.data.page.list
          this.totalPage = res.data.page.totalCount
        }
      })
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pamars.limit = val
      this.getList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pamars.page = val
      this.getList()
    },
    // 查询
    getDataList() {
      this.pamars.page = 1
      this.getList()
    },
    exportAll() {
      this.$confirm(`确定进行导出操作吗?`, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          let token = Vue.cookie.get('token')
          debugger
          window.location.href = `${this.$config.SERVER_URL}/admin/withdraw/export?business_code=${this.pamars.business_code}&verify_status=${this.pamars.verify_status}&token=${token}`
        })
        .catch(() => {})
    }
  }
}
</script>
